package com.mrjy.custom.bo;

import com.mrjy.common.entity.*;
import com.mrjy.common.util.ConstantsUtil;
import com.mrjy.common.util.GlobalConstant;
import com.mrjy.common.util.PolyvTokenUtil;
import com.mrjy.common.util.RedisUtil;
import com.mrjy.coursepackage.dao.ICoursePackageInfoDao;
import com.mrjy.coursepackage.dao.ICoursePackageVipDao;
import com.mrjy.coursepackage.dao.IUserCoursePackageDao;
import com.mrjy.custom.dao.ICustomModuleDao;
import com.mrjy.custom.dto.CustomModuleCoursePackageDto;
import com.mrjy.custom.dto.CustomModuleDto;
import com.mrjy.maintain.dao.IPartnerInfoDao;
import com.mrjy.maintain.dao.ITeacherInfoDao;
import com.mrjy.maintain.dao.IUserInfoDao;
import com.mrjy.maintain.dao.IUserScancodeInfoDao;
import com.mrjy.queries.dao.IQuestionTypeRelDao;
import com.mrjy.share.dao.IDistributorInfoDao;
import com.mrjy.share.dao.IDistributorTeamInfoDao;
import com.mrjy.share.dto.DistributorInfoDTO;
import com.mrjy.video.dao.IUserVideoRelDao;
import com.mrjy.video.dao.IVideoInfoDao;
import com.mrjy.video.dao.IVideoVipDao;
import com.mrjy.video.dto.StundentRankingDTO;
import com.mrjy.wechat.conts.WxConsts;
import com.tencent.common.Util;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("customModuleBo")
public class CustomModuleBo implements ICustomModuleBo {
	
	@Resource
	private ICustomModuleDao customModuleDao;
	
	@Resource
	private IVideoInfoDao videoInfoDao;
    @Resource
    private IUserVideoRelDao userVideoRelDao;
    @Resource
    private IUserCoursePackageDao userCoursePackageDao;
    @Resource
    private IQuestionTypeRelDao iQuestionTypeRelDao;
    @Resource
    private IUserInfoDao userInfoDao;
    @Resource
    private IDistributorInfoDao distributorInfoDao;
    @Resource
    private IPartnerInfoDao partnerInfoDao;
    @Resource
    private IDistributorTeamInfoDao distributorTeamInfoDao;
    @Resource
    private IUserScancodeInfoDao userScanCodeInfoDao;
    @Resource
    private ITeacherInfoDao teacherInfoDao;
    @Resource
    private ICoursePackageInfoDao coursePackageInfoDao;
    @Resource
    private ICoursePackageVipDao coursePackageVipDao;
    @Resource
    private IVideoVipDao videoVipDao;

    @Override
    public Object queryPageJPCourse(CustomModuleDto moduleDto) {
        Map<String, Object> map = new HashMap<String, Object>();
		if(null == moduleDto){
			map.put("err_code", "4001");
			map.put("err_msg", "传入参数信息不存在");
			return map;
		}
		
		List<CustomModuleDto> list = customModuleDao.queryPageCustomModule(moduleDto);
		if(null != list && list.size() > 0 ){
			map.put("err_code", "0");
			map.put("err_msg", "查询成功");
			map.put("rows", list);
			return map;
		}else{
			map.put("err_code", "4002");
			map.put("err_msg", "查询无数据");
			map.put("rows", null);
			return map;
		}
	}

	@Override
	public Object queryPageFreeVideo(CustomModuleDto module) {
		Map<String, Object> map = new HashMap<String, Object>();
		if(null == module){
			map.put("err_code", "4001");
			map.put("err_msg", "传入参数信息不存在");
			return map;
		}
		
		List<CustomModuleDto> list = customModuleDao.queryPageCustomModule(module);
		if(null != list && list.size() > 0 ){
			map.put("err_code", "0");
			map.put("err_msg", "查询成功");
			map.put("rows", list);
			return map;
		}else{
			map.put("err_code", "4002");
			map.put("err_msg", "查询无数据");
			map.put("rows", null);
			return map;
		}
	}

	@Override
	public Object queryPageCustomModule(CustomModuleDto module) {
		Map<String, Object> map = new HashMap<String, Object>();
		if(null==module.getCmType()){
			map.put("err_code", "400");
			map.put("err_msg", "参数异常");
			return map;
		}
		List<CustomModuleDto> list = null;
		if (module.getCmType()==1||module.getCmType()==2) { 
			list = customModuleDao.queryPageCustomModule(module);
            int count = customModuleDao.countPageCustomModule(module);
            map.put("count", count);
            for (CustomModuleDto dto : list) {
				if (RedisUtil.isVideoVip(module.getUserId(), dto.getCmProgramId())) {
					dto.setIsVipStatus("1");
				}else {
					dto.setIsVipStatus("0");
				}
            }
			//查询poly视频接口相关信息
			PolyInfo polyInfo = null;
			for (CustomModuleDto dto : list) {
				polyInfo = RedisUtil.cache(dto.getCmProgramId()+"");
				dto.setPolyInfo(polyInfo);

                PolyvTokenUtil tokenUtil = null;
                try {
                    tokenUtil = PolyvTokenUtil.cloneSimplePolyInfo(dto.getVideoCode(), dto.getAudioCode(),
                            Util.getHostIp(Util.getInetAddress()),
                            module.getUserId().toString(), "123", "1225");
                } catch (CloneNotSupportedException e) {
                    e.printStackTrace();
                }
                dto.setPolyvTokenUtil(tokenUtil);

                dto.setAudioCode(null);
                dto.setVideoCode(null);
            }
		}else if (module.getCmType()==3) {
			list = customModuleDao.queryPageCustomModule2(module);
            int count = customModuleDao.countPageCustomModule2(module);
            map.put("count", count);
        }else {
            map.put("err_code", "201");
            map.put("err_msg", "查询无数据");
			map.put("rows", null);
		}
		if (list != null && list.size()>0) {
			map.put("err_code", "0");
			map.put("err_msg", "查询成功,有数据");
			map.put("rows", list);
		}else {
            map.put("err_code", "201");
            map.put("err_msg", "查询无数据");
            map.put("rows", null);
        }
		return map;
	}

	@Override
	public Object insert(CustomModuleDto module,HttpSession session) {
		Map<String, Object> map = new HashMap<String, Object>();
		UserInfo loginUser = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);
		if(null == loginUser ){
			map.put("err_code", -1);
			map.put("err_msg", "用户未登录");
			return map;
		}
		// 数据校验
		if (module.getCmType() == null) {
			map.put("err_code", 401);
			map.put("err_msg", "类型不能为空");
			return map;
		}
		if (module.getCmType()==1||module.getCmType()==2) {
			if (module.getCmProgramId() == null) {
				map.put("err_code", 400);
				map.put("err_msg", "视频不能为空");
				return map;
			}
		}
		if (module.getCmType()==3) {
			if (module.getCmProgramId() == null) {
				map.put("err_code", 400);
				map.put("err_msg", "课程包不能为空");
				return map;
			}
		}
		if (module.getCmSortOne() == null) {
			map.put("err_code", 402);
			map.put("err_msg", "排序不能为空");
			return map;
		}
		if(module.getFreeStartTime() == null || module.getFreeStartTime() == ""){
       	 	map.put("err_code", 405);
            map.put("err_msg", "限时免费起始时间不能为空");
            return map;
	    }
	    if(module.getFreeEndTime() == null || module.getFreeEndTime() == ""){
	      	map.put("err_code", 406);
	        map.put("err_msg", "限时免费结束时间不能为空");
	        return map;
	    }
	    if((module.getFreeStartTime() != null && module.getFreeStartTime() !="") && (module.getFreeEndTime() != null && module.getFreeEndTime() !="")){
	    	try {
	    	        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	    	        Date date1 = simpleDateFormat.parse(module.getFreeStartTime());
	    	        Date date2 = simpleDateFormat.parse(module.getFreeEndTime());
	    	        long ts1 = date1.getTime();
	    	        long ts2 = date2.getTime();
	    	        if(ts1 >  ts2){
	    	        	map.put("err_code", 407);
	    		        map.put("err_msg", "限时免费起始时间不能大于结束时间");
	    		        return map;
	    	        }
			} catch (Exception e) {
				e.printStackTrace();
			}
	    }
		//查询是否已存在相关记录
		List<CustomModuleDto> list = customModuleDao.checkDuplicate(module);
		if (list!=null && list.size()>0) { //已存在记录
			map.put("err_code", 403);
			map.put("err_msg", "已存在相关记录,请勿重复添加");
			return map;
		}
		module.setCreateTime(new Timestamp(System.currentTimeMillis()));
		module.setDisableFlag(0);
		//1 - 精品课  2 - 免费试听 3-明师课程  4 - 亲子关系
		if (module.getCmType()==1) { 
			module.setCmName("精品课");
		}
		if (module.getCmType()==2) { 
			module.setCmName("免费试听");
			//将videoInfo的freeFlag设为1,单价设为0  0:收费  1:免费
			VideoInfo videoInfo = new VideoInfo();
			videoInfo.setId(module.getCmProgramId());
			videoInfo.setFreeFlag(1);
			videoInfoDao.updateById(videoInfo);

		}
		if (module.getCmType()==3) { 
			module.setCmName("明师课程");
		}
		if (module.getCmType()==4) { 
			module.setCmName("亲子关系");
		}
        if (module.getCmType() == 5) {
            module.setCmName("提问标签");
        }
        int row = customModuleDao.insertSelective(module);
        if (row > 0) {
            map.put("err_code", 200);
			map.put("err_msg", "添加成功");
		}else {
			map.put("err_code", 500);
			map.put("err_msg", "添加失败");
		}
		return map;
	}

	@Override
	public Object queryVideoByTeacher(String teacherId) {
		return customModuleDao.queryVideoByTeacher(teacherId);
	}

	@Override
	public Object queryAllTeacher(String teacherName,String flag) {
		return customModuleDao.queryAllTeacher(teacherName,flag);
	}

	@Override
	public Object listByPage(CustomModuleDto module,HttpSession session) {
		Map<String, Object> map= new HashMap<String, Object>();
		UserInfo loginUser = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);
        if (null == loginUser) {
            map.put("err_code", -1);
            map.put("err_msg", "用户未登录");
			return map;
		}
		int total = customModuleDao.queryCount(module);
		if (total>0) {
			if (module.getCmType()==1||module.getCmType()==2) { //1精品课,2免费试听
				map.put("rows",customModuleDao.queryPageCustomModuleForBack(module));
			}
			if (module.getCmType()==3) {  //3课程包
                List<CustomModuleCoursePackageDto> customModuleDtos = customModuleDao.queryPageCustomModuleForBack2(module);
                map.put("rows", customModuleDtos);
            }
            map.put("err_code", 0);
            map.put("err_msg", "查询成功,有数据");
		}else {
			map.put("err_code", 1);
			map.put("err_msg", "查询无数据");
		}
		map.put("total", total);
		return map;
	}
	
	@Override
	public Object getTotal(CustomModuleDto module) {
		return customModuleDao.queryCount(module);
	}

	@Override
	public Object updateDisableFlag(CustomModuleDto module,HttpSession session) {
		Map<String, Object> map= new HashMap<String, Object>();
		UserInfo loginUser = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);
		if(null == loginUser ){
			map.put("err_code", -1);
			map.put("err_msg", "用户未登录");
			return map;
		}
		if (module.getCmType()==null||module.getDisableFlag()==null) {
            map.put("err_code", 400);
            map.put("err_msg", "参数异常");
            return map;
		}
		if (module.getCmType()==2 && module.getCmProgramId()==null) {
			map.put("err_code", 401);
			map.put("err_msg", "参数缺少cmProgramId");
			return map;
		}
		VideoInfo videoInfo = new VideoInfo();
		if (module.getCmType()==2 && module.getDisableFlag()==1) {  //免费试听禁用后, 将freeFlag置为0
			videoInfo.setId(module.getCmProgramId());
			videoInfo.setFreeFlag(0);
			videoInfo.setOriginalPrice(5d);
			videoInfoDao.updateById(videoInfo);
		}
		if (module.getCmType()==2 && module.getDisableFlag()==0) {  //免费试听启用,freeFlag=1
			videoInfo.setId(module.getCmProgramId());
			videoInfo.setFreeFlag(1);
			videoInfo.setOriginalPrice(0d);
			videoInfoDao.updateById(videoInfo);
		}
		int row = customModuleDao.updateByPrimaryKeySelective(module);
		if (row>0) {
			map.put("err_code", 200);
			map.put("err_msg", "操作成功");
		}else{
			map.put("err_code", 500);
			map.put("err_msg", "操作失败");
		}
		return map;
	}

	@SuppressWarnings("unused")
	@Override
	public Object updateById(CustomModuleDto module,HttpSession session) {
		Map<String, Object> map = new HashMap<String, Object>();
		UserInfo loginUser = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);
		if(null == loginUser ){
			map.put("err_code", -1);
			map.put("err_msg", "用户未登录");
			return map;
		}
		// 数据校验
		if (module.getCmType()==1||module.getCmType()==2) {
			if (module.getCmProgramId() == null) {
				map.put("err_code", 400);
				map.put("err_msg", "视频不能为空");
				return map;
			}
		}
		if (module.getCmType()==3) {
			if (module.getCmProgramId() == null) {
				map.put("err_code", 400);
				map.put("err_msg", "课程包不能为空");
				return map;
			}
		}
		if (module.getCmSortOne() == null) {
			map.put("err_code", 402);
			map.put("err_msg", "排序不能为空");
			return map;
		}
		if(module.getCmType().equals(2)){//限时免费逻辑判断
			if(module.getFreeStartTime() == null || module.getFreeStartTime() == ""){
	       	 	map.put("err_code", 405);
	            map.put("err_msg", "限时免费起始时间不能为空");
	            return map;
		    }
		    if(module.getFreeEndTime() == null || module.getFreeEndTime() == ""){
		      	map.put("err_code", 406);
		        map.put("err_msg", "限时免费结束时间不能为空");
		        return map;
		    }
		    if((module.getFreeStartTime() != null && module.getFreeStartTime() !="") && (module.getFreeEndTime() != null && module.getFreeEndTime() !="")){
		    	try {
		    	        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		    	        Date date1 = simpleDateFormat.parse(module.getFreeStartTime());
		    	        Date date2 = simpleDateFormat.parse(module.getFreeEndTime());
		    	        long ts1 = date1.getTime();
		    	        long ts2 = date2.getTime();
		    	        if(ts1 >  ts2){
		    	        	map.put("err_code", 407);
		    		        map.put("err_msg", "限时免费起始时间不能大于结束时间");
		    		        return map;
		    	        }
				} catch (Exception e) {
					e.printStackTrace();
				}
		    }
		}
		
        if (module.getCmProgramIdTwo() != null) {
            module.setCmProgramIdTwo(module.getCmProgramIdTwo().replaceAll(",", ";"));
        }
        if (module.getCmLabelAlias() != null) {
            module.setCmLabelAlias(module.getCmLabelAlias().replaceAll(",", ";"));
        }
        int row = customModuleDao.updateByPrimaryKeySelective(module);
        if (row > 0) {
        	if(module.getCmType().equals(2)){//修改视频的freeflag
        		VideoInfo videoInfo = new VideoInfo();
        		videoInfo.setId(module.getCmProgramId());
        		videoInfo.setFreeFlag(1);
        		int count = videoInfoDao.updateVideoFreeFlag(videoInfo);
        		if(count>0){
        			map.put("err_video_msg", "视频状态修改成功");
        		}else{
        			map.put("err_video_msg", "视频状态修改失败");
        		}
        	}
            map.put("err_code", 200);
			map.put("err_msg", "修改成功");
		}else{
			map.put("err_code", 500);
			map.put("err_msg", "修改失败");
		}
		return map;
	}

	@Override
	public Object deleteByIds(CustomModuleDto module, HttpSession session) {
		Map<String, Object> map = new HashMap<String, Object>();
		if (module.getIds()==null) {
			map.put("err_code", 400);
			map.put("err_msg", "请勾选要操作的记录");
			return map;
		}
		int row = customModuleDao.deleteByIds(module);
		if (row>0) {
			map.put("err_code", 0);
			map.put("err_msg", "成功删除"+row+"条记录");
		}else {
			map.put("err_code", 1);
			map.put("err_msg", "删除失败");
		}
		return map;
	}

    @Override
    public Object insertTopic(CustomModuleDto module, HttpSession session) {
        Map<String, Object> map = new HashMap<String, Object>();
        UserInfo loginUser = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);
        if (null == loginUser) {
            map.put("err_code", -1);
            map.put("err_msg", "用户未登录");
            return map;
        }
        // 数据校验
        if (module.getCmProgramIdTwo() == null) {
            map.put("err_code", 401);
            map.put("err_msg", "话题标签名关联ids不能为空");
            return map;
        } else if (module.getCmProgramIdTwo() != null) {
            module.setCmProgramIdTwo(module.getCmProgramIdTwo().replaceAll(",", ";"));
        }
        if (module.getCmSortOne() == null) {
            map.put("err_code", 402);
            map.put("err_msg", "排序不能为空");
            return map;
        }
        if (module.getCmAliasName() == null) {
            map.put("err_code", 403);
            map.put("err_msg", "话题名不能为空");
            return map;
        }
        if (module.getCmLabelAlias() == null) {
            map.put("err_code", 404);
            map.put("err_msg", "标签名不能为空");
            return map;
        } else {
            module.setCmLabelAlias(module.getCmLabelAlias().replaceAll(",", ";"));
        }
        
        module.setCreateTime(new Timestamp(new Date().getTime()));
        module.setDisableFlag(0);
        module.setCmType(5);
        module.setCmName("提问标签");
        int row = customModuleDao.insertSelective(module);
        if (row > 0) {
            map.put("err_code", 200);
            map.put("err_msg", "添加成功");
        } else {
            map.put("err_code", 500);
            map.put("err_msg", "添加失败");
        }
        return map;
    }

	@Override
	public Object queryTopicById(CustomModuleDto module, HttpSession session) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<String, Object>();
		List<CustomModuleDto> list =  customModuleDao.queryTopicById(module);
		if(list !=null && list.size() > 0){
			map.put("err_code", 0);
			map.put("err_msg", "查询成功");
			map.put("rows", list);
		}else{
			map.put("err_code", 1);
			map.put("err_msg", "查询失败");
		}
		return map;
	}


    @Override
    public Object queryPercentFinish(CustomModuleDto module, HttpSession session) {
        Map<String, Object> map = new HashMap<String, Object>();
        List<CustomModuleDto> list = customModuleDao.queryPercentFinish(module);
        if (list != null && list.size() > 0) {
            map.put("err_code", 0);
            map.put("err_msg", "查询成功");
            map.put("rows", list);
        } else {
            map.put("err_code", 1);
            map.put("err_msg", "查询失败");
        }
        return map;
    }

    @Override
    public Object querySummaryByUserId(CustomModuleDto customModuleDto) {
        Map<String, Object> map = new HashMap<String, Object>();
        List<CustomModuleDto> list = customModuleDao.querySummaryByUserId(customModuleDto);

        if (null == customModuleDto.getUserId()) {
            map.put("err_code", 500);
            map.put("err_msg", "参数出错");
            return map;
        }
        //辅导员
        DistributorInfoDTO distributorInfoDTO = distributorInfoDao.queryByUserId(customModuleDto.getUserId());//是不是分销商
        UserInfo userInfo = userInfoDao.querySimpleInfoById(Integer.parseInt(ConstantsUtil.getProperty("DA_SHAN_ID")));//大山
        userInfo.setIsTeacher(1);
//        if (distributorInfoDTO == null || distributorInfoDTO.getDistributorType().equals("0")) {
//            //普通推广者,还有可能是家人
//            DistributorTeamInfoDTO distributorTeamInfoDTO = new DistributorTeamInfoDTO();
//            distributorTeamInfoDTO.setUserId(customModuleDto.getUserId());
//            distributorTeamInfoDTO = distributorTeamInfoDao.queryInfoByUserId(distributorTeamInfoDTO);//存在就说明是团队成员
//
//            if (distributorTeamInfoDTO == null) {
//                //说明不是团队成员
//                UserScancodeInfoDto dto = new UserScancodeInfoDto();
//                dto.setUserId(customModuleDto.getUserId());
//                UserScancodeInfoDto userScancodeInfoDto = userScanCodeInfoDao.queryPromoterByUserId(dto);//查处辅导员
//                //userScancodeInfoDto 还可以没有扫过码的
//                if (userScancodeInfoDto == null) {
//                    map.put("info", userInfo);
//                } else {
//                    map.put("info", userScancodeInfoDto);
//                }
//            } else {
//                //说明是团队成员，是团队成员，说有有自定领导
//                Integer belongTeamId = distributorTeamInfoDTO.getBelongTeamId();
//                UserInfo promoterUserInfo = userInfoDao.querySimpleInfoById(belongTeamId);
//                TeacherInfo teacherInfo = new TeacherInfo();
//                teacherInfo.setUserId(promoterUserInfo.getId());
//                TeacherInfo promoterTeacherInfo = teacherInfoDao.queryByUserId(teacherInfo);
//                if (promoterTeacherInfo == null) {
//                    promoterUserInfo.setIsTeacher(0);
//                } else {
//                    promoterUserInfo.setIsTeacher(1);
//                }
//
//                map.put("info", promoterUserInfo);
//            }
//
//        } else {
//            map.put("info", userInfo);
//        }
        map.put("info", userInfo);
        //家长合格证
        int parentCert = customModuleDao.queryParentCertificationByUserId(customModuleDto);
        map.put("parentCert", parentCert);
        //已购
        CoursePackageVip vip = new CoursePackageVip();
        vip.setUserId(customModuleDto.getUserId());
        VideoVip videoVip = new VideoVip();
        videoVip.setUserId(customModuleDto.getUserId());
        int pay_course = coursePackageVipDao.queryCountUserPaidCPByUserid(vip);
        int pay_weclass = videoVipDao.countHasPurchase(videoVip);
        int has_purchase = pay_course + pay_weclass;

        //已学
        int learned_num = userVideoRelDao.queryTotalFinishedVideoCountByUserId(customModuleDto.getUserId());
        if (list != null && list.size() > 0) {
            map.put("has_purchase", has_purchase);
            map.put("err_code", 200);
            map.put("err_msg", "查询有数据");
            map.put("rows", list);
            map.put("learned_num", learned_num);
        } else {
            map.put("has_purchase", has_purchase);
            map.put("err_code", 500);
            map.put("err_msg", "查询没有数据");
            map.put("rows", list);
            map.put("learned_num", learned_num);
        }
        return map;
    }

    @Override
    public Object queryParentCertificationByUserId(CustomModuleDto customModuleDto, HttpSession session) {
        Map<String, Object> map = new HashMap<String, Object>();

        int count = customModuleDao.queryParentCertificationByUserId(customModuleDto);
        map.put("err_code", 200);
        map.put("err_msg", "查询有数据");
        map.put("result", count);// 0 : 没有 1：拥有
        return map;
    }

    @Override
    public Object queryCustomTopicInfoByUserId(UserCoursePackageRel userCoursePackageRel, HttpSession session) {
        Map<String, Object> map = new HashMap<String, Object>();
        UserInfo loginUser = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);
        if (null == loginUser) {
            map.put("err_code", -1);
            map.put("err_msg", "用户未登录");
            return map;
        }
        int classmates = userCoursePackageDao.countClassmate(userCoursePackageRel);//同学数量
        userCoursePackageRel.setUserId(loginUser.getId());
        List<UserCoursePackageRel> list = userCoursePackageDao.queryClassmate(userCoursePackageRel);
        CustomModule module = new CustomModule();
        module.setId(userCoursePackageRel.getCustomModuleId());
        int totalQuestion = iQuestionTypeRelDao.countByCustomId(module);//发帖总数
        int totalAnswer = iQuestionTypeRelDao.sumCommonNumByCustomId(module);//回帖总数

        map.put("classmates", classmates);
        map.put("chatCount", totalAnswer + totalQuestion);
        if (list != null && list.size() > 0) {
            map.put("courseCount", list.get(0).getRelateCount());
            map.put("info", list.get(0));
        } else {
            map.put("courseCount", 0);
            map.put("info", null);
        }
        return map;
    }
}
